package org.miyuki4j.cfgtool;

import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * @Desc
 * @Author miyuki4j
 * @Date 2025/8/1/星期五 16:06
 * @Version 1.0
 */
public class ExceptionUtil {

    public static String getStackTrace(String header, Throwable e) {
        StringWriter sw = new StringWriter(1024);
        PrintWriter pw = new PrintWriter(sw);
        if (StringUtils.isNotBlank(header)) {
            pw.write(header + ":\n");
        }
        e.printStackTrace(pw);
        IOUtils.closeQuietly(pw);
        return sw.toString();
    }

    public static String getStackTrace(Throwable e) {
        return getStackTrace("", e);
    }
}
